package io.jpress.module.article.service.provider;

import io.jboot.aop.annotation.Bean;
import io.jboot.db.model.Columns;
import io.jpress.commons.service.JPressServiceBase;
import io.jpress.module.article.model.ArticleFlowStatus;
import io.jpress.module.article.service.ArticleFlowStatusService;

import java.util.List;

@Bean
public class ArticleFlowStatusServiceProvider extends JPressServiceBase<ArticleFlowStatus> implements ArticleFlowStatusService {

    @Override
    public List<ArticleFlowStatus> findListByArticleId(Long articleId) {
        Columns columns = Columns.safeCreate("article_id",articleId);
        return DAO.findListByColumns(columns);
    }

    @Override
    public ArticleFlowStatus findByProcessInstanceId(String processInstanceId) {
        Columns columns = Columns.safeCreate("flow_process_instance_id",processInstanceId);
        return DAO.findFirstByColumns(columns);
    }

    @Override
    public List<ArticleFlowStatus> findRunningByArticleId(Long articleId) {
        Columns columns = Columns.safeCreate("article_id",articleId)
                .le("status",ArticleFlowStatus.STATUS_RUNNING);
        return DAO.findListByColumns(columns);
    }


}